import requests
import json


# 请求的URL，WebHook地址
webhook = "https://oapi.dingtalk.com/robot/send?access_token=39f4b69bb13db7a9d2ea82f079d809b66d957e73077fa694999f8724d4c97aea"
#构建请求头部
header = {
        "Content-Type": "application/json",
        "Charset": "UTF-8"
}


def sendDD(msg='', keyword='小派', at_all=False):
    text = '%s:%s' % (keyword, msg)
    message = {
        "msgtype": "text",
        "text": {
            "content": text
        },
        "at": {
            "isAtAll": at_all
        }
    }
    # 对请求的数据进行json封装
    message_json = json.dumps(message)
    # 发送请求
    info = requests.post(url=webhook, data=message_json, headers=header)
    # 打印返回的结果
    print(info.text)
